package com.mrd.gtimp.query.action;

import com.mrd.exception.QueryException;
import com.mrd.framework.ui.filter.Filter;
import com.mrd.gtimp.sup.entity.SupShipMentMaterial;
import com.mrd.gtimp.sup.service.SupShipMentMaterialBiz;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

import javax.annotation.Resource;

/**
 * <p> application name: gtimp <p> copyright: Copyright@2012 明睿达科技有限公司
 */

/**
 * @author luob
 */

@Controller
@RequestMapping("/query")
public class ShipMentMaterialQueryAction {
    private static final long serialVersionUID = 1L;
    @Resource
    private SupShipMentMaterialBiz supShipMentMaterialBiz;

    private SupShipMentMaterial supShipMentMaterial;

    private List<SupShipMentMaterial> supShipMentMaterials;

    private String jsonString;

    /**
     * public String show() {
     * try {
     * page = initPage(SupShipMentMaterialBiz.findEntityCount(filters));
     * Order order = new Order();
     * order.add(sidx, sord);
     * SupShipMentMaterials = SupShipMentMaterialBiz
     * .findEntityByFilter(page.getCurrentPageStartNo(), page.getPageSize(), filters, order);
     * } catch (Exception e) {
     * e.printStackTrace();
     * }
     * return SUCCESS;
     * }
     **/

    /**
     * 默认访问入口
     */
    @RequestMapping("/shipMentMaterialQuery-main")
    public String main() {
        return "/gtimp/query/shipMentMaterialQueryList";
    }

    /**
     * 编辑信息
     */
    @RequestMapping("/shipMentMaterialQuery-find")
    public String find() {
        if (null != supShipMentMaterial) {
            if (StringUtils.isNotEmpty(supShipMentMaterial.getID())) {
                try {
                    supShipMentMaterial = supShipMentMaterialBiz.findEntityById(supShipMentMaterial
                            .getID());
                } catch (QueryException e) {
                    e.printStackTrace();
                }
            }
        }
        //// TODO: 2016/8/13  json
        return null;
    }

    /**
     * 查询
     */
    @RequestMapping("/shipMentMaterialQuery-findList")
    public String findList(Filter filters) {
        // String comId = user.getCompany().getId();// get from user
        //// TODO: 2016/8/15  order page
//        try {
//            if (null != filters && filters.getRules() != null) {
//                boolean hasShipCom = false;
//                boolean hasOwner = false;
//                for (SearchRule rule : filters.getRules()) {
//                    if ("shipCompany.id".equals(rule.getField())) {
//                        hasShipCom = true;
//                    } else if ("owner.id".equals(rule.getField())) {
//                        hasOwner = true;
//                    }
//                }
//                page = initPage(supShipMentMaterialBiz.findEntityCount(filters));
//                Order order = new Order();
//                if (null != sidx && !"".equals(sidx)) {
//                    order.add(sidx, sord);
//                }
//                if (hasOwner && hasShipCom) {
//                    page.setPageSize(1);
//                    order.add("CTIME", "desc");
//                }
//                supShipMentMaterials = supShipMentMaterialBiz.findEntityByFilter(page
//                        .getCurrentPageStartNo(), page.getPageSize(), filters, order);
//            }
//        } catch (QueryException e) {
//            e.printStackTrace();
//        }
        // ModelPrinter.print(supShipMentMaterials);
        //// TODO: 2016/8/15  json
//        return "gridData";
        return null;
    }

    @Resource
    public void setSupShipMentMaterialBiz(SupShipMentMaterialBiz supShipMentMaterialBiz) {
        this.supShipMentMaterialBiz = supShipMentMaterialBiz;
    }

    public SupShipMentMaterial getSupShipMentMaterial() {
        return supShipMentMaterial;
    }

    public void setSupShipMentMaterial(SupShipMentMaterial supShipMentMaterial) {
        this.supShipMentMaterial = supShipMentMaterial;
    }

    public String getJsonString() {
        return jsonString;
    }

    public void setJsonString(String jsonString) {
        this.jsonString = jsonString;
    }

    public List<SupShipMentMaterial> getSupShipMentMaterials() {
        return supShipMentMaterials;
    }

    public void setSupShipMentMaterials(List<SupShipMentMaterial> supShipMentMaterials) {
        this.supShipMentMaterials = supShipMentMaterials;
    }
}
